package m3u8

import (
	"gitee.com/kaylee595/m3u8/token"
)

type KeyMethod string

const (
	KeyMethodNONE      KeyMethod = "NONE"
	KeyMethodAES128    KeyMethod = "AES-128"
	KeyMethodSAMPLEAES KeyMethod = "SAMPLE-AES"
)

type Key struct {
	Method KeyMethod
	URI    string
	IV     []byte
}

const (
	keyNameMethod = "METHOD"
	keyNameURI    = "URI"
	keyNameIV     = "IV"
)

func ParseKey(attrs token.Attributes) *Key {
	return &Key{
		Method: KeyMethod(attrs[keyNameMethod]),
		URI:    attrs[keyNameURI].FromString(),
		IV:     attrs[keyNameIV].FromHex(),
	}
}
